package database

import (
	"context"
	"fmt"

	"github.com/neo4j/neo4j-go-driver/v5/neo4j"
)

func GetLlmPrivilegeUsers() ([]string, error) {
	var privilegeUsers []string
	cypher := "match (n:Constant{name:\"llmPrivilegeUsers\"}) return n"
	session := Neo4jDriver.NewSession(neo4j.SessionConfig{
		AccessMode: neo4j.AccessModeRead,
	})
	defer session.Close(context.TODO())

	result, err := session.Run(context.TODO(), cypher, nil)
	if err != nil {
		fmt.Println(err.Error())
		return privilegeUsers, err
	}

	for (result.Next(context.TODO())) {
		n, _ := result.Record().Get("n")
		node := n.(neo4j.Node)

		values := node.Props["value"].([]interface{})

		for _, name := range values {
			privilegeUsers = append(privilegeUsers, name.(string))
		}
	}

	return privilegeUsers, nil
}